package com.baizan.daka.ui.presenter

import com.baizan.daka.base.BasePresenter
import com.baizan.daka.mvp.model.MeModel
import com.baizan.daka.ui.contract.LoginContract
import com.baizan.daka.mvp.model.UserModel
import com.baizan.daka.mvp.model.bean.LoginInfoBean
import com.baizan.daka.rx.Subscriber.CommonSubscriber
import com.baizan.daka.showToast
import com.baizan.daka.ui.contract.AddBankContract
import com.baizan.daka.util.Md5

class AddBankPresenter(val mView: AddBankContract.View) : BasePresenter(),
    AddBankContract.Presenter {


    private val meModel: MeModel by lazy {
        MeModel()
    }

    override fun addBank(
        cardNo: String, bankName: String,
        bankBranch: String, bankUser: String

    ) {
        mView.showLoadingDialog()
        meModel.addBank(cardNo, bankName, bankBranch, bankUser)
            .subscribe(object : CommonSubscriber<Any>(compositeDisposable) {
                override fun onCallNext(t: Any?) {
                    mView.addBankSuccess()
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }
            })
    }

    override fun modifyBank(
        id: Long,
        cardNo: String,
        bankName: String,
        bankBranch: String,
        bankUser: String
    ) {
        mView.showLoadingDialog()
        meModel.modifyBank(id, cardNo, bankName, bankBranch, bankUser)
            .subscribe(object : CommonSubscriber<Any>(compositeDisposable) {
                override fun onCallNext(t: Any?) {
                    mView.addBankSuccess()
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }
            })
    }


}

